<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Discount_model extends CI_Model {
	
	function get_discount_list(){
		
		$q = $this->db->get('sdk_discount');
		return $q->result();
	}
	
	function insert_discount($discount_code,$discount_price,$expire_time){
		
		$this->db->insert('sdk_discount',array('discount_code'=>$discount_code,'discount_price'=>$discount_price,'expire_time'=>$expire_time,'create_time'=>time()));
		
		return $this->db->affected_rows()>0?true:false;
	}
	
	function code_exists($discount_code){
		
		$q = $this->db->get_where('sdk_discount',array('discount'=>$discount_code));
		
		return $q->num_rows()>0?true:false;
	}
	
	function get_discount($discount_code){
		
		$q = $this->db->get_where('sdk_discount',array('discount_code'=>$discount_code));
		
		return $q->row();
	}
}
